// 体验使用 express 处理客户端请求

const port = 8080; // 指定端口

const express = require('express');
// console.log(typeof(express), express.length);
const bodyParser = require('body-parser')

let app = express();
// console.log(app);

// 这里参照 express-generator 创建的目录结构，使用 public 目录当作静态资源根目录
app.use(express.static('public')); // 处理静态资源

// 解析 application/x-www-form-urlencoded 表单中包含的数据到 req.body 中
app.use(bodyParser.urlencoded({ extended: false }));

app.get('/list', (req, resp) => {
    console.log(req.method, req.url, req.protocol + '/' + req.httpVersion);
    console.log(req.query);
    resp.send('<p>' + Date.now() + '</p>');
});

app.post('/list', (req, resp) => {
    console.log(req.method, req.url, req.protocol);
    console.log(req.body);
    resp.send('<p>' + Date.now() + '</p>');
});

app.listen(port);